/**
 * @param {number[]} time
 * @param {number} totalTrips
 * @return {number}
 */
 var minimumTime = function(time, totalTrips) {
  if(time.length === 1) {
    return time[0] * totalTrips
  }
  time.sort((a,b) => a-b)
  let l = 0, r = totalTrips * time[0]
  while(l < r) {
    let m = (l + r) >> 1
    if(check(m)) {
      r = m
    } else {
      l = m+1
    }
  }
  return l
  function check(x) {
    let sum = 0
    for(let t of time) {
      sum += Math.floor(x/t)
    }
    return sum >= totalTrips
  }
};